import {createApp} from 'vue'
import store from '@/stores/index.js'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import '@/theme.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'

import App from './App.vue'
import router, {registerRouter} from './router'
import {useAdminStore} from "@/stores/admin.js";

const app = createApp(App)

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}

const localAuth = ['add', 'edit', 'delete']
//全局自定义指令
app.directive('auth', {
    mounted(el, binding) {
        const {value} = binding;
        if (value && !localAuth.includes(value)) {
            el.parentNode.removeChild(el);
        }
    }
})



app.use(ElementPlus)
app.use(store)
//要在挂载之前注册路由
if (useAdminStore().getMenu().length !== 0) {
    registerRouter(useAdminStore().getMenu())
}
app.use(router)
app.mount('#app')
